<!DOCTYPE html>
<html>
<head>
    

    

    



    <meta charset="utf-8">
    
    
    
    
    <title>定时发送微信订阅消息 | 马丹丹的博客</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#3F51B5">
    
    
    <meta name="keywords" content="Python,微信">
    <meta name="description" content="微信小程序的消息推送从之前的模板消息更新到了现在的订阅消息，本篇文章就教你怎么使用小程序订阅消息，文后会附上使用python写的定时发送订阅消息的代码。 1.首先要添加一个订阅消息模板登陆上微信小程序的后台，选择订阅消息   选择一个适合自己的模板   然后就能得到我们的模板ID   2.给小程序添加获取权限的代码这里文档上写的很清楚，在某个点击事件的地方之类的添加获取权限的代码 官方文档链接：">
<meta property="og:type" content="article">
<meta property="og:title" content="定时发送微信订阅消息">
<meta property="og:url" content="http:&#x2F;&#x2F;mddcloud.cn&#x2F;2020&#x2F;04&#x2F;04&#x2F;%E5%AE%9A%E6%97%B6%E5%8F%91%E9%80%81%E5%BE%AE%E4%BF%A1%E8%AE%A2%E9%98%85%E6%B6%88%E6%81%AF&#x2F;index.html">
<meta property="og:site_name" content="马丹丹的博客">
<meta property="og:description" content="微信小程序的消息推送从之前的模板消息更新到了现在的订阅消息，本篇文章就教你怎么使用小程序订阅消息，文后会附上使用python写的定时发送订阅消息的代码。 1.首先要添加一个订阅消息模板登陆上微信小程序的后台，选择订阅消息   选择一个适合自己的模板   然后就能得到我们的模板ID   2.给小程序添加获取权限的代码这里文档上写的很清楚，在某个点击事件的地方之类的添加获取权限的代码 官方文档链接：">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https:&#x2F;&#x2F;s1.ax1x.com&#x2F;2020&#x2F;04&#x2F;04&#x2F;Gwfm0x.png">
<meta property="og:image" content="https:&#x2F;&#x2F;s1.ax1x.com&#x2F;2020&#x2F;04&#x2F;04&#x2F;GwfKAK.png">
<meta property="og:image" content="https:&#x2F;&#x2F;s1.ax1x.com&#x2F;2020&#x2F;04&#x2F;04&#x2F;Gwfn76.png">
<meta property="og:image" content="https:&#x2F;&#x2F;res.wx.qq.com&#x2F;wxdoc&#x2F;dist&#x2F;assets&#x2F;img&#x2F;request-subscribe-message.3851318e.jpg">
<meta property="og:image" content="https:&#x2F;&#x2F;s1.ax1x.com&#x2F;2020&#x2F;04&#x2F;07&#x2F;GgJAeO.png">
<meta property="og:image" content="https:&#x2F;&#x2F;s1.ax1x.com&#x2F;2020&#x2F;04&#x2F;04&#x2F;Gwo06e.png">
<meta property="article:published_time" content="2020-04-04T08:15:36.000Z">
<meta property="article:modified_time" content="2020-04-07T08:37:04.501Z">
<meta property="article:author" content="马丹丹">
<meta property="article:tag" content="Python">
<meta property="article:tag" content="微信">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https:&#x2F;&#x2F;s1.ax1x.com&#x2F;2020&#x2F;04&#x2F;04&#x2F;Gwfm0x.png">
    
        <link rel="alternate" type="application/atom+xml" title="马丹丹的博客" href="/atom.xml">
    
    <link rel="shortcut icon" href="/img/favicon.png">
    <link rel="stylesheet" href="//unpkg.com/hexo-theme-material-indigo@latest/css/style.css">
    <script>window.lazyScripts=[]</script>

    <!-- custom head -->
    

<meta name="generator" content="Hexo 4.1.0"></head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu" class="hide" >
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap" style="background-image:url(/img/brand.jpg)">
      <div class="brand">
        <a href="/" class="avatar waves-effect waves-circle waves-light">
          <img src="/img/avatar.jpg">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">马丹丹</h5>
          <a href="mailto:mdd12138@163.com" title="mdd12138@163.com" class="mail">mdd12138@163.com</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/"  >
                <i class="icon icon-lg icon-home"></i>
                主页
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/archives"  >
                <i class="icon icon-lg icon-archives"></i>
                Archives
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/tags"  >
                <i class="icon icon-lg icon-tags"></i>
                Tags
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://github.com/zhongjidalao" target="_blank" >
                <i class="icon icon-lg icon-github"></i>
                Github
              </a>
            </li>
        
      </ul>
    </div>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">定时发送微信订阅消息</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="输入感兴趣的关键字">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">定时发送微信订阅消息</h1>
        <h5 class="subtitle">
            
                <time datetime="2020-04-04T08:15:36.000Z" itemprop="datePublished" class="page-time">
  2020-04-04
</time>


            
        </h5>
    </div>

    


</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap post-toc-shrink" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#1-首先要添加一个订阅消息模板"><span class="post-toc-number">1.</span> <span class="post-toc-text">1.首先要添加一个订阅消息模板</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#2-给小程序添加获取权限的代码"><span class="post-toc-number">2.</span> <span class="post-toc-text">2.给小程序添加获取权限的代码</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#3-发送订阅消息"><span class="post-toc-number">3.</span> <span class="post-toc-text">3.发送订阅消息</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#1-我们先看看官方给出的api"><span class="post-toc-number">3.0.1.</span> <span class="post-toc-text">1.我们先看看官方给出的api</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#2-获取ACCESS-TOKEN"><span class="post-toc-number">3.0.2.</span> <span class="post-toc-text">2.获取ACCESS_TOKEN</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#3-测试发送订阅消息"><span class="post-toc-number">3.0.3.</span> <span class="post-toc-text">3.测试发送订阅消息</span></a></li></ol></li></ol></li></ol>
        </nav>
    </aside>


<article id="post-定时发送微信订阅消息"
  class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">定时发送微信订阅消息</h1>
        <div class="post-meta">
            <time class="post-time" title="2020-04-04 16:15:36" datetime="2020-04-04T08:15:36.000Z"  itemprop="datePublished">2020-04-04</time>

            


            
<span id="busuanzi_container_page_pv" title="文章总阅读量" style='display:none'>
    <i class="icon icon-eye icon-pr"></i><span id="busuanzi_value_page_pv"></span>
</span>


        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <p> 微信小程序的消息推送从之前的模板消息更新到了现在的订阅消息，本篇文章就教你怎么使用小程序订阅消息，文后会附上使用python写的定时发送订阅消息的代码。</p>
<h3 id="1-首先要添加一个订阅消息模板"><a href="#1-首先要添加一个订阅消息模板" class="headerlink" title="1.首先要添加一个订阅消息模板"></a>1.首先要添加一个订阅消息模板</h3><p>登陆上微信小程序的后台，选择订阅消息</p>
<img src="https://s1.ax1x.com/2020/04/04/Gwfm0x.png" alt="Gwfm0x.png" />

<p>选择一个适合自己的模板</p>
<img src="https://s1.ax1x.com/2020/04/04/GwfKAK.png" width="80%" alt="GwfKAK.png" border="0" />

<p>然后就能得到我们的模板ID</p>
<img src="https://s1.ax1x.com/2020/04/04/Gwfn76.png" alt="Gwfn76.png" border="0" />

<h3 id="2-给小程序添加获取权限的代码"><a href="#2-给小程序添加获取权限的代码" class="headerlink" title="2.给小程序添加获取权限的代码"></a>2.给小程序添加获取权限的代码</h3><p>这里文档上写的很清楚，在某个点击事件的地方之类的添加获取权限的代码</p>
<p>官方文档链接：<a href="https://developers.weixin.qq.com/miniprogram/dev/api/open-api/subscribe-message/wx.requestSubscribeMessage.html" target="_blank" rel="noopener">点击这里</a></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">wx.requestSubscribeMessage(&#123;</span><br><span class="line">  tmplIds: [<span class="string">''</span>],</span><br><span class="line">  success (res) &#123; &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>用户点击后的效果是这样的，用户点击一次，获取一次发送订阅消息的权限</p>
<img src="https://res.wx.qq.com/wxdoc/dist/assets/img/request-subscribe-message.3851318e.jpg" />

<h3 id="3-发送订阅消息"><a href="#3-发送订阅消息" class="headerlink" title="3.发送订阅消息"></a>3.发送订阅消息</h3><p>官方文档链接：<a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html" target="_blank" rel="noopener">点击这里</a></p>
<h5 id="1-我们先看看官方给出的api"><a href="#1-我们先看看官方给出的api" class="headerlink" title="1.我们先看看官方给出的api"></a>1.我们先看看官方给出的api</h5><blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">POST https:&#x2F;&#x2F;api.weixin.qq.com&#x2F;cgi-bin&#x2F;message&#x2F;subscribe&#x2F;send?access_token&#x3D;ACCESS_TOKEN</span><br></pre></td></tr></table></figure>
</blockquote>
<p>可以看到这个api的调用需要先获取ACCESS_TOKEN，我们就先来看看怎么获取到ACCESS_TOKEN，这里官方也给出了api</p>
<h5 id="2-获取ACCESS-TOKEN"><a href="#2-获取ACCESS-TOKEN" class="headerlink" title="2.获取ACCESS_TOKEN"></a>2.获取ACCESS_TOKEN</h5><blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">GET https:&#x2F;&#x2F;api.weixin.qq.com&#x2F;cgi-bin&#x2F;token?grant_type&#x3D;client_credential&amp;appid&#x3D;APPID&amp;secret&#x3D;APPSECRET</span><br></pre></td></tr></table></figure>
</blockquote>
<p>我们需要填上小程序的appid和secret并给这个链接发送一个get请求，这样就会给我们返回ACCESS_TOKEN</p>
<p>我们可以用postman测试一下这个api</p>
<img src="https://s1.ax1x.com/2020/04/07/GgJAeO.png" alt="GgJAeO.png" border="0" />

<p>可以看到成功的获取到了access_token，我们把他填入发送订阅消息时需要的api中，这个api是一个post请求，官方也给出了需要发送的数据，可以去官方文档中查看</p>
<h5 id="3-测试发送订阅消息"><a href="#3-测试发送订阅消息" class="headerlink" title="3.测试发送订阅消息"></a>3.测试发送订阅消息</h5><p>我们得到了订阅消息模板ID，access_token，就可以根据文档给出的数据发送订阅，这里使用postman测试</p>
<img src="https://s1.ax1x.com/2020/04/04/Gwo06e.png" alt="Gwo06e.png" border="0" />

<p>这样就可以发送订阅消息了</p>
<p>最后给出我写的定时发送小程序订阅消息的代码：<a href="https://github.com/zhongjidalao/wechat_subscribe" target="_blank" rel="noopener">https://github.com/zhongjidalao/wechat_subscribe</a></p>
<p>在GitHub中，大家自取，如果有问题可以发送Issues，如果觉得写的不错可以点一下star</p>

        </div>

        <blockquote class="post-copyright">
    
    <div class="content">
        
<span class="post-time">
    最后更新时间：<time datetime="2020-04-07T08:37:04.501Z" itemprop="dateUpdated">2020-04-07 16:37:04</time>
</span><br>


        
        本页地址：<a href="/2020/04/04/%E5%AE%9A%E6%97%B6%E5%8F%91%E9%80%81%E5%BE%AE%E4%BF%A1%E8%AE%A2%E9%98%85%E6%B6%88%E6%81%AF/" target="_blank" rel="external">http://mddcloud.cn/2020/04/04/%E5%AE%9A%E6%97%B6%E5%8F%91%E9%80%81%E5%BE%AE%E4%BF%A1%E8%AE%A2%E9%98%85%E6%B6%88%E6%81%AF/</a>
        
    </div>
    
    <footer>
        <a href="http://mddcloud.cn">
            <img src="/img/avatar.jpg" alt="马丹丹">
            马丹丹
        </a>
    </footer>
</blockquote>

        


        <div class="post-footer">
            
	<ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Python/" rel="tag">Python</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%BE%AE%E4%BF%A1/" rel="tag">微信</a></li></ul>


            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://mddcloud.cn/2020/04/04/%E5%AE%9A%E6%97%B6%E5%8F%91%E9%80%81%E5%BE%AE%E4%BF%A1%E8%AE%A2%E9%98%85%E6%B6%88%E6%81%AF/&title=《定时发送微信订阅消息》 — 马丹丹的博客&pic=http://mddcloud.cn/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://mddcloud.cn/2020/04/04/%E5%AE%9A%E6%97%B6%E5%8F%91%E9%80%81%E5%BE%AE%E4%BF%A1%E8%AE%A2%E9%98%85%E6%B6%88%E6%81%AF/&title=《定时发送微信订阅消息》 — 马丹丹的博客&source=" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://mddcloud.cn/2020/04/04/%E5%AE%9A%E6%97%B6%E5%8F%91%E9%80%81%E5%BE%AE%E4%BF%A1%E8%AE%A2%E9%98%85%E6%B6%88%E6%81%AF/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《定时发送微信订阅消息》 — 马丹丹的博客&url=http://mddcloud.cn/2020/04/04/%E5%AE%9A%E6%97%B6%E5%8F%91%E9%80%81%E5%BE%AE%E4%BF%A1%E8%AE%A2%E9%98%85%E6%B6%88%E6%81%AF/&via=http://mddcloud.cn" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://mddcloud.cn/2020/04/04/%E5%AE%9A%E6%97%B6%E5%8F%91%E9%80%81%E5%BE%AE%E4%BF%A1%E8%AE%A2%E9%98%85%E6%B6%88%E6%81%AF/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between flex-row-reverse">
  

  
    <div class="waves-block waves-effect next">
      <a href="/2020/01/29/leetcode%E4%B8%A4%E6%95%B0%E4%B9%8B%E5%92%8C/" id="post-next" class="post-nav-link">
        <div class="tips">Next <i class="icon icon-angle-right icon-lg icon-pl"></i></div>
        <h4 class="title">leetcode两数之和</h4>
      </a>
    </div>
  
</nav>



    




















</article>



</div>

        <footer class="footer">
    <div class="top">
        
<p>
    <span id="busuanzi_container_site_uv" style='display:none'>
        站点总访客数：<span id="busuanzi_value_site_uv"></span>
    </span>
    <span id="busuanzi_container_site_pv" style='display:none'>
        站点总访问量：<span id="busuanzi_value_site_pv"></span>
    </span>
</p>


        <p>
            
                <span><a href="/atom.xml" target="_blank" class="rss" title="rss"><i class="icon icon-lg icon-rss"></i></a></span>
            
            <span>博客内容遵循 <a rel="license noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" target="_blank">知识共享 署名 - 非商业性 - 相同方式共享 4.0 国际协议</a></span>
        </p>
    </div>
    <div class="bottom">
        <p><span>马丹丹 &copy; 2019 - 2020</span>
            <span>
                
                <a href="http://www.miitbeian.gov.cn/" target="_blank">豫ICP备17025066号</a><br>
                
                Power by <a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/yscoder/hexo-theme-indigo" target="_blank">indigo</a>
            </span>
        </p>
    </div>
</footer>

    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://mddcloud.cn/2020/04/04/%E5%AE%9A%E6%97%B6%E5%8F%91%E9%80%81%E5%BE%AE%E4%BF%A1%E8%AE%A2%E9%98%85%E6%B6%88%E6%81%AF/&title=《定时发送微信订阅消息》 — 马丹丹的博客&pic=http://mddcloud.cn/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://mddcloud.cn/2020/04/04/%E5%AE%9A%E6%97%B6%E5%8F%91%E9%80%81%E5%BE%AE%E4%BF%A1%E8%AE%A2%E9%98%85%E6%B6%88%E6%81%AF/&title=《定时发送微信订阅消息》 — 马丹丹的博客&source=" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://mddcloud.cn/2020/04/04/%E5%AE%9A%E6%97%B6%E5%8F%91%E9%80%81%E5%BE%AE%E4%BF%A1%E8%AE%A2%E9%98%85%E6%B6%88%E6%81%AF/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《定时发送微信订阅消息》 — 马丹丹的博客&url=http://mddcloud.cn/2020/04/04/%E5%AE%9A%E6%97%B6%E5%8F%91%E9%80%81%E5%BE%AE%E4%BF%A1%E8%AE%A2%E9%98%85%E6%B6%88%E6%81%AF/&via=http://mddcloud.cn" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://mddcloud.cn/2020/04/04/%E5%AE%9A%E6%97%B6%E5%8F%91%E9%80%81%E5%BE%AE%E4%BF%A1%E8%AE%A2%E9%98%85%E6%B6%88%E6%81%AF/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/', SHARE: true, REWARD: false };


</script>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/main.min.js"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/search.min.js" async></script>






<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>



<script>
(function() {
    var OriginTitile = document.title, titleTime;
    document.addEventListener('visibilitychange', function() {
        if (document.hidden) {
            document.title = '死鬼去哪里了！';
            clearTimeout(titleTime);
        } else {
            document.title = '(つェ⊂)咦!又好了!';
            titleTime = setTimeout(function() {
                document.title = OriginTitile;
            },2000);
        }
    });
})();
</script>



</body>
</html>
